package org.example;

import java.sql.*;

/**
 * Hive JDBC基础示例
 */
public class HiveHelloWorld {
    public static void main(String[] args) {
//        ResultSet resultSet = null;
//        Statement statement = null;
//        Connection conn = null;
        try {
            //注册驱动
            Class.forName("org.apache.hive.jdbc.HiveDriver");
            //建立连接
            Connection conn = DriverManager.getConnection(
                    "jdbc:hive2://192.168.134.130:10000/test",
                    "hive1",
                    "Master123!!"
            );
            //创建语句
            Statement statement = conn.createStatement();
            //SQL
            String sql = "show tables";
            //执行查询
            ResultSet resultSet = statement.executeQuery(sql);
            //遍历结果集
            while (resultSet.next()) {
                System.out.println(resultSet.getString(1));
            }
            conn.close();
            statement.close();
            resultSet.close();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
